<template>
  <view>
    <button @tap="handleTap('picker3')">选择代理地区</button>
			您选择的地区是:<view>{{province}}{{city}}{{area}}</view>
    <lb-picker ref="picker3"
      v-model="value3"
      mode="multiSelector"
      :list="list"
      :level="3"
      @change="handleChange"
      @confirm="handleConfirm"
      @cancel="handleCancel">
    </lb-picker>
		<button type="default" @click="setAjax">提交</button>
  </view>
</template>

<script>
	import LbPicker from '@/components/lb-picker'
	import areaData from './area-data-min'
	export default {
		components: {
		      LbPicker
		    },
		data(){
			return {
				value3: [],
				list: areaData,
				province:'',
				city:'',
				area:'',
				openid:'',
			}
    },
		onLoad() {
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
				},
				fail: () => {
					uni.navigateTo({
						url: '../../../login/login'
					});
				}
			});
		},
		methods: {
			setAjax(){
				uni.request({
					url: 'https://app.t9y9y9.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.vip.submit&app=1',
					method: 'POST',
					data: {
						'openid':this.openid,
						'province':this.province,
						'city':this.city,
						'area':this.area,
						},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						console.log(res)
						if(res.data.error==0){
							uni.showToast({
								title:res.data.message,
								icon:'none'
							})
							setTimeout(()=>{
								uni.switchTab({
									url:'../member'
								})
							},2500)
						}else{
							uni.showToast({
								title:res.data.message,
								icon:'none'
							})
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			handleTap (picker) {
				this.$refs[picker].show()
			},
			handleChange (item) {
				console.log('change::', item)
			},
			handleConfirm (item) {
				console.log('confirm::', item.item[0].label,item.item[1].label,item.item[2].label)
				this.province = item.item[0].label
				this.city = item.item[1].label
				this.area = item.item[2].label
			},
			handleCancel (item) {
				console.log('cancel::', item)
			}
		}
	}
</script>
